package com.xxxcompany.blog.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.xxxcompany.blog.entity.User;

@WebServlet("/index")
public class IndexServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("text/html;charset=utf-8");
		PrintWriter pw = resp.getWriter();
		
		HttpSession session = req.getSession();
		User u = (User)session.getAttribute("user");
		
		if(u!=null)
		{
			pw.print("欢迎你,"+u.getUsername());
			
			pw.print("<a href='logout'>登出</a>");
			
			// 首页 
			// 文章列表  新建博问 
			// 打印出所有博客文章标题
		}
		else
		{
			pw.print("欢迎你,游客<br />");
			
			pw.print("<a href='login.html'>登录</a>");
		}
		
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}